package com.taotao.web;

import com.taotao.common.EasyUIResult;
import com.taotao.common.TaotaoResult;
import com.taotao.service.TbItemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/item/param")
public class TbItemParamController {
    @Autowired
    private TbItemParamService tbItemParamService;

    /**
     * 查询所有的规格模板
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public EasyUIResult getTbItemParamList(@RequestParam("page") int pageNum, @RequestParam("rows") int pageSize){
        EasyUIResult easyUIResult = tbItemParamService.getTbItemParamList(pageNum,pageSize);
        return easyUIResult;
    }

    /**
     * 查询商品类目对应的规格模板
     * @param id
     * @return
     */
    @RequestMapping("/query/itemcatid/{id}")
    @ResponseBody
    public TaotaoResult getTbItemParamByItemCatId(@PathVariable long id){
        TaotaoResult paramData = tbItemParamService.getTbItemParamByItemCatId(id);
        return paramData;
    }

    /**
     * 添加商品类目对应的规格模板
     * @param itemCatId
     * @param paramData
     * @return
     */
    @RequestMapping("/save/{itemCatId}")
    @ResponseBody
    public TaotaoResult addTbItemParam(@PathVariable long itemCatId,String paramData){
        TaotaoResult taotaoResult = tbItemParamService.addTbItemParam(itemCatId,paramData);
        return taotaoResult;
    }

    /**
     * 删除规格模板
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteTbItemParam(long[] ids){
        TaotaoResult taotaoResult = tbItemParamService.deleteTbItemParam(ids);
        return taotaoResult;
    }
}
